#!/bin/bash

if [ $# -ne 3 ]; 
then
	echo "" 
	echo "ATTENTION: nombre d'arguments invalide !!!!"
	echo ""
	echo "USAGE: ./exo20.sh file1 keyword resultfile"
	echo ""
	exit -1;
fi

if [ -f $1 -a  -f $3 ];
then
	echo "" 
        echo "les fichiers des "$1" et "$3" existent!"
	echo "" 
else
	echo "" 
	echo "ATTENTION: les deux fichiers [$1] et [$3] doivent exister"
	echo "" 
	exit -1
fi

nb_lignes=`cat "$1" | grep $2 | wc -l`

if [ $nb_lignes -gt 0 ];
then
	echo ""
        echo " * Creation fichier [$3] contenant les lignes avec le mot cherché! *"
	echo ""

	cat "$1" | grep $2 > "$3"
else
	echo ""
	echo "WARNING: "
        echo " Keyword [$2] not found in file [$1] ! *"
	echo ""

fi

exit #pour quitter le script
